Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix self profiler ICE on Windows #56170

Merged
merged 2 commits into from
Nov 25, 2018

Conversation

wesleywiser
Copy link
Member

Fixes #51648

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 22, 2018
@rust-highfive

This comment has been minimized.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a couple of nitpicks, r=me.

src/librustc/util/profiling.rs Outdated Show resolved Hide resolved
src/librustc/util/profiling.rs Outdated Show resolved Hide resolved
if self.opts.debugging_opts.self_profile {
let mut profiler = self.self_profiling.borrow_mut();
f(&mut profiler);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change needed? (Not that it's wrong, just surprised it wasn't already the case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed per se. It wasn't already the case because we showed a very small amount of overhead from turning on the profiler. I think it's probably best to make it opt-in though.

@michaelwoerister
Copy link
Member

❤️ ❤️ ❤️

On Windows, the high-resolution timestamp api doesn't seem to always be
monotonic. This can cause panics when the self-profiler uses the
`Instant` api to find elapsed time.

Work around this by detecting the case where now is less than the start
time and just use 0 elapsed ticks as the measurement.

Fixes rust-lang#51648
@wesleywiser
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Nov 25, 2018

📌 Commit dce1c45 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 25, 2018
…ws, r=estebank

Fix self profiler ICE on Windows

Fixes rust-lang#51648
bors added a commit that referenced this pull request Nov 25, 2018
Rollup of 14 pull requests

Successful merges:

 - #56024 (Don't auto-inline const functions)
 - #56045 (Check arg/ret sizedness at ExprKind::Path)
 - #56072 (Stabilize macro_literal_matcher)
 - #56075 (Encode a custom "producers" section in wasm files)
 - #56100 (generator fields are not necessarily initialized)
 - #56101 (Incorporate `dyn` into more comments and docs.)
 - #56144 (Fix BTreeSet and BTreeMap gdb pretty-printers)
 - #56151 (Move a flaky process test out of libstd)
 - #56170 (Fix self profiler ICE on Windows)
 - #56176 (Panic setup msg)
 - #56204 (Suggest correct enum variant on typo)
 - #56207 (Stabilize the int_to_from_bytes feature)
 - #56210 (read_c_str should call the AllocationExtra hooks)
 - #56211 ([master] Forward-ports from beta)

Failed merges:

r? @ghost
@bors bors merged commit dce1c45 into rust-lang:master Nov 25, 2018
Copy link

@IntrepidPig IntrepidPig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be an error with how this workaround was applied. This is my first time delving in to rustc though so I could be way off the mark, sorry if that's the case.

Also, I just remembered: I think this issue is present on many more platforms than just windows and would be better handled by modifying the elapsed function in libstd or wherever it is, as well as editing the documentation and remove the statement that guarantees them to be nondecreasing.

if self.current_timer >= now {
Duration::new(0, 0)
} else {
self.current_timer.elapsed()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this line (209) be changed to do now - self.current_timer instead? I think right now it's susceptible to the same error the workaround is meant to prevent. Since Instant::elapsed will call Instant::now again, which could be inaccurate and won't be double-checked like the variable now just was.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a reasonable change to me

@wesleywiser
Copy link
Member Author

@IntrepidPig The real work around here for all platforms not just Windows was the first commit:

b319715 Disable the self-profiler unless the -Z self-profile flag is set

None of the bug reports we've received so far have indicated that the user was actually trying to run the profiler, the were just trying to compile some code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants